package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketAdmin;
import com.supermarket.business.dto.SupermarketAdminDTO;
import com.supermarket.business.vo.SupermarketAdminVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketAdminService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;

/**
 * 系统管理员Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/admin")
public class SupermarketAdminController extends BaseController
{
    @Resource
    private ISupermarketAdminService sysAdminService;

    /**
     * 查询系统管理员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketAdminDTO supermarketAdminDTO)
    {
        startPage();
        SupermarketAdmin supermarketAdmin = new SupermarketAdmin();
        BeanUtils.copyProperties(supermarketAdminDTO, supermarketAdmin);
        List<SupermarketAdmin> list = sysAdminService.selectSysAdminList(supermarketAdmin);
        return getDataTable(list);
    }

    /**
     * 导出系统管理员列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:export')")
    @Log(title = "系统管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketAdmin supermarketAdmin)
    {
        List<SupermarketAdmin> list = sysAdminService.selectSysAdminList(supermarketAdmin);
        ExcelUtil<SupermarketAdmin> util = new ExcelUtil<SupermarketAdmin>(SupermarketAdmin.class);
        util.exportExcel(response, list, "系统管理员数据");
    }

    /**
     * 获取系统管理员详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:query')")
    @GetMapping(value = "/{adminId}")
    public AjaxResult getInfo(@PathVariable("adminId") Long adminId)
    {
        return sysAdminService.selectSysAdminVOByAdminId(adminId);
    }

    /**
     * 新增系统管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:add')")
    @Log(title = "系统管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupermarketAdminDTO supermarketAdminDTO)
    {
        SupermarketAdmin supermarketAdmin = new SupermarketAdmin();
        BeanUtils.copyProperties(supermarketAdminDTO, supermarketAdmin);
        return toAjax(sysAdminService.insertSysAdmin(supermarketAdmin));
    }

    /**
     * 修改系统管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:edit')")
    @Log(title = "系统管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupermarketAdminDTO supermarketAdminDTO)
    {
        SupermarketAdmin supermarketAdmin = new SupermarketAdmin();
        BeanUtils.copyProperties(supermarketAdminDTO, supermarketAdmin);
        return toAjax(sysAdminService.updateSysAdmin(supermarketAdmin));
    }

    /**
     * 删除系统管理员
     */
    @PreAuthorize("@ss.hasPermi('supermarket:admin:remove')")
    @Log(title = "系统管理员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adminIds}")
    public AjaxResult remove(@PathVariable Long[] adminIds)
    {
        return toAjax(sysAdminService.deleteSysAdminByAdminIds(adminIds));
    }
}
